package com.mall.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.common.base.utils.MapUtil;
import com.mall.common.base.utils.PageBuilder;
import com.mall.common.base.utils.PageUtil;
import com.mall.goods.entity.EvaluationEntity;
import com.mall.goods.entity.GoodsEntity;
import com.mall.goods.mapper.EvaluationMapper;
import com.mall.goods.service.EvaluationService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

@Service("evaluationService")
public class EvaluationServiceImpl extends ServiceImpl<EvaluationMapper, EvaluationEntity>
        implements EvaluationService {

    @Autowired
    private EvaluationMapper evaluationMapper;

    @Override
    public int saveEvaluation(EvaluationEntity evaluation) {
        evaluation.setEvaluateTime(new Date());
        return evaluationMapper.insert(evaluation);
    }

    @Override
    public PageUtil queryPage(Integer pageNum, Integer pageSize, Long memberId) {
        Map<String,Object> pageParams = new MapUtil().put("pageNum",pageNum).put("pageSize",pageSize);
        Page<EvaluationEntity> page = (Page<EvaluationEntity>)new PageBuilder<EvaluationEntity>().getPage(pageParams);
        QueryWrapper<EvaluationEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(memberId != null, "member_id", memberId);
        IPage<EvaluationEntity> iPage = baseMapper.queryPage(page, wrapper);
        return new PageUtil(iPage);
    }
}
